﻿'Copyright (C) 2010  Thomas Huebner
'
'This program is free software
'
'you can redistribute it and/or modify it under the terms 
'of the GNU General Public License as published by the 
'Free Software Foundation either version 2 of the License, 
'or (at your option) any later version.
'
'This program is distributed in the hope that it will be 
'useful, but WITHOUT ANY WARRANTY without even the implied 
'warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
'See the GNU General Public License for more details.
'
'You should have received a copy of the GNU General Public License 
'along with this program; if not, write to the 
'Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
'Boston, MA 02111-1307, USA. 


Imports System.Xml.Serialization
Imports System.IO
Imports System.Text
Imports System.ComponentModel


Public Class LF_InitiativeListConverter

    '''
    ''' <summary>Read a String to LF_InitiativeList object </summary>
    ''' <param name="text" >XML Source as string</param>
    ''' <returns>LF_InitiativeList object</returns>
    '''
    Public Shared Function ReadInitiativeList(ByVal text As String) As LF_InitiativeList
        Dim xs As New XmlSerializer(GetType(LF_InitiativeList))
        Dim tr As TextReader = New StringReader(text)
        Return DirectCast(xs.Deserialize(tr), LF_InitiativeList)
    End Function

    '''
    ''' <summary>Write an LF_InitiativeList object to XML string</summary>
    ''' <param name="oLF_InitiativeList" >LF_InitiativeList object</param>
    ''' <returns>XML Source as string</returns>
    '''
    Public Shared Function WriteInitiativeList(ByVal oLF_InitiativeList As LF_InitiativeList) As String
        Dim xs As New XmlSerializer(GetType(LF_InitiativeList))
        Dim sb As New StringBuilder()
        Dim tw As TextWriter = New StringWriter(sb)
        xs.Serialize(tw, oLF_InitiativeList)
        Return tw.ToString
    End Function

End Class

''' <summary>
''' Array of Initiatives
''' </summary>
''' <remarks></remarks>
<XmlRoot("initiative_list")> _
Public Class LF_InitiativeList

    <XmlNamespaceDeclarations()> _
        Public namespaces As XmlSerializerNamespaces

    <XmlAttribute("version")> _
        Public version As String

    <XmlElement("initiative")> _
        Public items As LF_Initiative()

End Class

''' <summary>
''' Single Initiative
''' </summary>
''' <remarks></remarks>
Public Class LF_Initiative

    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("area_id")> _
        Public _AreaID As String

    ''' <summary>
    ''' Id of the area
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property AreaID() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._AreaID) Then
                Return CInt(Me._AreaID)
            Else
                Return 0
            End If
        End Get
    End Property

    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("area_name")> _
        Public _AreaName As String

    ''' <summary>
    ''' Name of the area
    ''' </summary>
    ''' <value></value>
    ''' <returns>String</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property AreaName() As String
        Get
            If Not String.IsNullOrEmpty(Me._AreaName) Then
                Return Me._AreaID.Trim
            Else
                Return String.Empty
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("issue_id")> _
        Public _IssueID As String

    ''' <summary>
    ''' Id of the issue
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property IssueID() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._IssueID) Then
                Return CInt(Me._IssueID)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("issue_state")> _
        Public _IssueState As String

    ''' <summary>
    ''' Current state of the issue, valid values are: new accepted frozen voting finished cancelled.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property IssueState() As String
        Get
            If Not String.IsNullOrEmpty(Me._IssueState) Then
                Return _IssueState.Trim
            Else
                Return String.Empty
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("issue_created")> _
        Public _IssueCreated As String

    ''' <summary>
    ''' Point in time, when the issue has been created.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Datetime</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property IssueCreated() As DateTime
        Get
            If Not String.IsNullOrEmpty(Me._IssueCreated) Then
                Return DateTime.Parse(Me._IssueCreated)
            Else
                Return New Date
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("issue_accepted")> _
        Public _IssueAccepted As String

    ''' <summary>
    ''' Point in time, when one initiative of issue reached the "issue_quorum"
    ''' </summary>
    ''' <value></value>
    ''' <returns>DateTime</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property IssueAccepted() As DateTime
        Get
            If Not String.IsNullOrEmpty(Me._IssueAccepted) Then
                Return DateTime.Parse(Me._IssueAccepted)
            Else
                Return New Date
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("issue_half_frozen")> _
        Public _IssueHalfFrozen As String

    ''' <summary>
    ''' Point in time, when "discussion_time" has elapsed, or members voted for voting.
    ''' </summary>
    ''' <value></value>
    ''' <returns>DateTime</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property IssueHalfFrozen() As DateTime
        Get
            If Not String.IsNullOrEmpty(Me._IssueHalfFrozen) Then
                Return DateTime.Parse(Me._IssueHalfFrozen)
            Else
                Return DateAdd(DateInterval.Day, Me.IssueDiscussionTime, Me.IssueAccepted)
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("issue_fully_frozen")> _
        Public _IssueFullyFrozen As String

    ''' <summary>
    ''' Point in time, when "verification_time" has elapsed.
    ''' </summary>
    ''' <value></value>
    ''' <returns>DateTime</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property IssueFullyFrozen() As DateTime
        Get
            If Not String.IsNullOrEmpty(Me._IssueFullyFrozen) Then
                Return DateTime.Parse(Me._IssueFullyFrozen)
            Else
                Return DateAdd(DateInterval.Day, Me.IssueVerificationTime, Me.IssueHalfFrozen)
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("issue_closed")> _
        Public _IssueClosed As String

    ''' <summary>
    ''' Point in time, when "admission_time" or "voting_time" have elapsed, and issue is no longer active.
    ''' </summary>
    ''' <value></value>
    ''' <returns>DateTime</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property IssueClosed() As DateTime
        Get
            If Not String.IsNullOrEmpty(Me._IssueClosed) Then
                Return DateTime.Parse(Me._IssueClosed)
            Else
                Return DateAdd(DateInterval.Day, Me.IssueVotingTime, Me.IssueFullyFrozen)
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("issue_admission_time")> _
        Public _IssueAdmissionTime As String

    ''' <summary>
    ''' Maximum time an issue stays open without being "accepted"
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property IssueAdmissionTime() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._IssueAdmissionTime) Then
                If Me._IssueVotingTime.EndsWith("days") Then
                    Return CInt(Me._IssueAdmissionTime.Replace(" days", ""))
                Else
                    Dim strArr() = Me._IssueAdmissionTime.Split(":")
                    Return CInt(strArr(0)) \ 24
                End If
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("issue_discussion_time")> _
        Public _IssueDiscussionTime As String

    ''' <summary>
    ''' Regular time until an issue is "half_frozen" after being "accepted"
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property IssueDiscussionTime() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._IssueDiscussionTime) Then
                If Me._IssueVotingTime.EndsWith("days") Then
                    Return CInt(Me._IssueDiscussionTime.Replace(" days", ""))
                Else
                    Dim strArr() = Me._IssueDiscussionTime.Split(":")
                    Return CInt(strArr(0)) \ 24
                End If
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("issue_verification_time")> _
        Public _IssueVerificationTime As String

    ''' <summary>
    ''' Regular time until an issue is "fully_frozen" after being "half_frozen"
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property IssueVerificationTime() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._IssueVerificationTime) Then
                If Me._IssueVotingTime.EndsWith("days") Then
                    Return CInt(Me._IssueVerificationTime.Replace(" days", ""))
                Else
                    Dim strArr() = Me._IssueVerificationTime.Split(":")
                    Return CInt(strArr(0)) \ 24
                End If
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("issue_voting_time")> _
        Public _IssueVotingTime As String

    ''' <summary>
    ''' Time after an issue is "fully_frozen" but not "closed"
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property IssueVotingTime() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._IssueVotingTime) Then
                If Me._IssueVotingTime.EndsWith("days") Then
                    Return CInt(Me._IssueVotingTime.Replace(" days", ""))
                Else
                    Dim strArr() = Me._IssueVotingTime.Split(":")
                    Return CInt(strArr(0)) \ 24
                End If
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("issue_ranks_available")> _
        Public _IssueRanksAvailable As String

    ''' <summary>
    ''' TRUE = ranks have been calculated
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property IssueRanksAvailable() As Boolean
        Get
            If Not String.IsNullOrEmpty(Me._IssueRanksAvailable) Then
                If Me._IssueRanksAvailable.Trim.ToUpper = "TRUE" Then
                    Return True
                End If
            End If

            Return False

        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("policy_issue_quorum_num")> _
        Public _PolicyIssueQuorumNum As String

    ''' <summary>
    ''' Numerator of potential supporter quorum to be reached by one 
    ''' initiative of an issue to be "accepted".
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property PolicyIssueQuorumNum() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._PolicyIssueQuorumNum) Then
                Return CInt(Me._PolicyIssueQuorumNum)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("policy_issue_quorum_den")> _
        Public _PolicyIssueQuorumDen As String

    ''' <summary>
    ''' Denumerator of potential supporter quorum to be reached by one 
    ''' initiative of an issue to be "accepted".
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property PolicyIssueQuorumDen() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._PolicyIssueQuorumDen) Then
                Return CInt(Me._PolicyIssueQuorumDen)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("policy_initiative_quorum_num")> _
        Public _PolicyInitiativeQuorumNum As String

    ''' <summary>
    ''' Numerator of satisfied supporter quorum to be reached by an 
    ''' initiative to be "admitted" for voting.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property PolicyInitiativeQuorumNum() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._PolicyInitiativeQuorumNum) Then
                Return CInt(Me._PolicyInitiativeQuorumNum)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("policy_initiative_quorum_den")> _
        Public _PolicyInitiativeQuorumDen As String

    ''' <summary>
    ''' Denumerator of satisfied supporter quorum to be reached by an 
    ''' initiative to be "admitted" for voting.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property PolicyInitiativeQuorumDen() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._PolicyInitiativeQuorumDen) Then
                Return CInt(Me._PolicyInitiativeQuorumDen)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("policy_majority_num")> _
        Public _PolicyMajorityNum As String

    ''' <summary>
    ''' Numerator of fraction of majority to be reached during voting by an 
    ''' initiative to be aggreed upon.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property PolicyMajorityNum() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._PolicyMajorityNum) Then
                Return CInt(Me._PolicyMajorityNum)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("policy_majority_den")> _
        Public _PolicyMajorityDen As String

    ''' <summary>
    ''' Denumerator of fraction of majority to be reached during voting by an 
    ''' initiative to be aggreed upon.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property PolicyMajorityDen() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._PolicyMajorityDen) Then
                Return CInt(Me._PolicyMajorityDen)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("policy_majority_strict")> _
        Public _PolicyMajorityStrict As String

    ''' <summary>
    ''' If TRUE, then the majority must be strictly greater 
    ''' than "majority_num"/"majority_den", otherwise it may also be equal.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property PolicyMajorityStrict() As Boolean
        Get
            If Not String.IsNullOrEmpty(Me._PolicyMajorityStrict) Then
                If Me._PolicyMajorityStrict.Trim.ToUpper = "TRUE" Then
                    Return True
                End If
            End If

            Return False

        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("id")> _
        Public _ID As String

    ''' <summary>
    ''' Id of the initiative.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property ID() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._ID) Then
                Return CInt(Me._ID)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("name")> _
        Public _Name As String

    ''' <summary>
    ''' Name (title) of the iniative.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Name() As String
        Get
            If Not String.IsNullOrEmpty(Me._Name) Then
                Return _Name.Trim
            End If

            Return String.Empty
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("discussion_url")> _
        Public _DiscussionURL As String

    ''' <summary>
    ''' URL to discussion page of the initiators.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property DiscussionURL() As String
        Get
            If Not String.IsNullOrEmpty(Me._DiscussionURL) Then
                Return _DiscussionURL.Trim
            End If

            Return String.Empty
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("created")> _
        Public _Created As String

    ''' <summary>
    ''' Timestamp of initiative creation.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Datetime</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Created() As DateTime
        Get
            If Not String.IsNullOrEmpty(Me._Created) Then
                Return DateTime.Parse(Me._Created)
            Else
                Return New Date
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("revoked")> _
        Public _Revoked As String

    ''' <summary>
    ''' Timestamp of initiative revokation. 'Nothing' if initiative isn't revoked.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Datetime</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Revoked() As DateTime
        Get
            If Not String.IsNullOrEmpty(Me._Revoked) Then
                Return DateTime.Parse(Me._Revoked)
            Else
                Return Nothing
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("suggested_initiative_id")> _
        Public _SuggestedInitiativeID As String

    ''' <summary>
    ''' The id of the initiative suggested by the initiators of a 
    ''' revoked initiative. -1 if not revoked or none suggested.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property SuggestedInitiativeID() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._SuggestedInitiativeID) Then
                Return CInt(Me._SuggestedInitiativeID)
            Else
                Return (-1)
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("admitted")> _
        Public _Admitted As String 'Boolean

    ''' <summary>
    ''' TRUE if "positive_votes"/("positive_votes"+"negative_votes") is 
    ''' strictly greater or greater-equal than initiative quorum.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Boolean</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Admitted() As Boolean
        Get
            If Not String.IsNullOrEmpty(Me._Admitted) Then
                If Me._Admitted.Trim.ToUpper = "TRUE" Then
                    Return True
                Else
                    Return False
                End If
            Else
                Return False
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("issue_population")> _
        Public _IssuePopulation As String

    ''' <summary>
    ''' Number of members interested in this issue.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property IssuePopulation() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._IssuePopulation) Then
                Return CInt(Me._IssuePopulation)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("supporter_count")> _
        Public _SupporterCount As String

    ''' <summary>
    ''' Number of members currently supporting the initiative.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property SupporterCount() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._SupporterCount) Then
                Return CInt(Me._SupporterCount)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("informed_supporter_count")> _
        Public _InformedSupporterCount As String

    ''' <summary>
    ''' Number of members currently supporting the latest draft of the initiative.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property InformedSupporterCount() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._InformedSupporterCount) Then
                Return CInt(Me._InformedSupporterCount)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("satisfied_supporter_count")> _
        Public _SatisfiedSupporterCount As String

    ''' <summary>
    ''' Number of members currently supporting the initiative and not having critical opinion.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property SatisfiedSupporterCount() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._SatisfiedSupporterCount) Then
                Return CInt(Me._SatisfiedSupporterCount)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("satisfied_informed_supporter_count")> _
        Public _SatisfiedInformedSupporterCount As String

    ''' <summary>
    ''' Number of members currently supporting the latest draft of the initiative and not having critical opinion.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property SatisfiedInformedSupporterCount() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._SatisfiedInformedSupporterCount) Then
                Return CInt(Me._SatisfiedInformedSupporterCount)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("issue_vote_now")> _
        Public _IssueVoteNow As String

    ''' <summary>
    ''' Number of votes in fravor of voting now.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property IssueVoteNow() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._IssueVoteNow) Then
                Return CInt(Me._IssueVoteNow)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("issue_vote_later")> _
        Public _IssueVoteLater As String

    ''' <summary>
    ''' Number of votes against voting now.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property IssueVoteLater() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._IssueVoteLater) Then
                Return CInt(Me._IssueVoteLater)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("issue_voter_count")> _
        Public _IssueVoterCount As String

    ''' <summary>
    ''' Total number of direct and delegating voters; 
    ''' This value is related to the final voting, while "population" is related 
    ''' to snapshots before the final voting.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property IssueVoterCount() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._IssueVoterCount) Then
                Return CInt(Me._IssueVoterCount)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("positive_votes")> _
        Public _PositiveVotes As String

    ''' <summary>
    ''' Number of positive votes for this initiative. Only available in issue state finished.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property PositiveVotes() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._PositiveVotes) Then
                If Not Me._PositiveVotes.ToUpper = "NULL" Then
                    Return CInt(Me._PositiveVotes)
                Else
                    Return 0
                End If
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("negative_votes")> _
        Public _NegativeVotes As String

    ''' <summary>
    ''' Number of negative votes for this initiative. Only available in issue state finished.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property NegativeVotes() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._NegativeVotes) Then
                If Not Me._NegativeVotes.ToUpper = "NULL" Then
                    Return CInt(Me._NegativeVotes)
                Else
                    Return 0
                End If
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("agreed")> _
        Public _Agreed As String 'Boolean

    ''' <summary>
    ''' TRUE if "positive_votes"/("positive_votes"+"negative_votes") is 
    ''' strictly greater or greater-equal than initiative quorum.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Boolean</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Agreed() As Boolean
        Get
            If Not String.IsNullOrEmpty(Me._NegativeVotes) Then
                If Me._Agreed.ToUpper = "TRUE" Then
                    Return True
                Else
                    Return False
                End If
            Else
                Return False
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("rank")> _
        Public _Rank As String

    ''' <summary>
    ''' Rank of approved initiatives (winner is 1).
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Rank() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._Rank) Then
                Return CInt(Me._Rank)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("current_draft_created")> _
        Public _CurrentDraftCreated As String

    ''' <summary>
    ''' Point in time, when the initiative draft was last updated.
    ''' </summary>
    ''' <value></value>
    ''' <returns>DateTime</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property CurrentDraftCreated() As DateTime
        Get
            If Not String.IsNullOrEmpty(Me._CurrentDraftCreated) Then
                Return DateTime.Parse(Me._CurrentDraftCreated)
            Else
                Return Nothing
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("current_draft_formatting_engine")> _
        Public _CurrentDraftFormattingEngine As String

    ''' <summary>
    ''' The wiki formatting engine used for the current draft version.
    ''' </summary>
    ''' <value></value>
    ''' <returns>String</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property CurrentDraftFormattingEngine() As String
        Get
            If Not String.IsNullOrEmpty(_CurrentDraftFormattingEngine) Then
                Return Me._CurrentDraftFormattingEngine.Trim.ToUpper
            End If

            Return "NONE"

        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("current_draft_content")> _
        Public _CurrentDraftContent As String

    ''' <summary>
    ''' The current draft itself
    ''' </summary>
    ''' <value></value>
    ''' <returns>String</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property CurrentDraftContent() As String
        Get
            If Not String.IsNullOrEmpty(_CurrentDraftContent) Then
                If CurrentDraftFormattingEngine.ToUpper = "HTML" Then
                    Return _CurrentDraftContent
                Else
                    Return _CurrentDraftContent.Replace(vbLf, vbNewLine)
                End If
            Else
                Return String.Empty
            End If
        End Get
    End Property

End Class

